<template>
  <div class="home-container">
    <div class="header-container">
      <h1 class="main-title">十二相整流发电机虚拟训练软件</h1>
      <div class="user-info">
        <span class="welcome-text"
          >欢迎，{{ userStore.userRealName || userStore.userName }}</span
        >
        <button class="logout-button" @click="handleLogout">注销</button>
      </div>
    </div>
    <div class="modules-container">
      <div class="module-circle" @click="goToModule('teaching')">
        <div class="layer-1"></div>
        <div class="layer-2"></div>
        <div class="layer-3"></div>
        <div class="module-content">
          <div class="module-icon">📚</div>
          <h2>原理教学</h2>
          <p>学习十二相整流发电机的基本原理和操作方法</p>
        </div>
      </div>
      <div class="module-circle" @click="goToModule('fault')">
        <div class="layer-1"></div>
        <div class="layer-2"></div>
        <div class="layer-3"></div>
        <div class="module-content">
          <div class="module-icon">⚙️</div>
          <h2>故障模拟系统</h2>
          <p>模拟各种故障情况，提高应急处理能力</p>
        </div>
      </div>
      <div class="module-circle" @click="goToModule('training')">
        <div class="layer-1"></div>
        <div class="layer-2"></div>
        <div class="layer-3"></div>
        <div class="module-content">
          <div class="module-icon">📝</div>
          <h2>训练考核教控管理</h2>
          <p>进行训练考核和教学控制管理</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { useUserStore } from "@/store/user";
import { onMounted } from "vue";

const router = useRouter();
const userStore = useUserStore();

// 组件挂载时恢复用户数据
onMounted(() => {
  userStore.restoreUserData();

  // 检查用户是否已登录，如果未登录则跳转到登录页
  // if (!userStore.isLogin) {
  //   router.push("/login");
  // }
});

const goToModule = (module) => {
  // 这里可以跳转到具体的模块页面
  console.log("进入模块:", module);
  // 根据模块跳转到不同页面
  if (module === "teaching") {
    router.push("/principle");
  } else if (module === "fault") {
    router.push("/trouble-shooting");
  } else if (module === "training") {
    router.push("/start-model");
  } else if (module === "control") {
    router.push("/full-control");
  }
  // 其他模块可以在这里添加
  // router.push(`/module/${module}`)
};

// 注销功能
const handleLogout = () => {
  // 使用user store进行注销
  userStore.logout();

  // 跳转到登录页面
  router.push("/login");
};
</script>

<style scoped>
.home-container {
  min-height: 100vh;
  background-image: url("@/assets/home.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.header-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 20px;
  position: relative;
}

.main-title {
  font-size: 36px;
  color: white;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  font-weight: bold;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
  position: absolute;
  right: 0;
}

.welcome-text {
  color: white;
  font-size: 18px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.logout-button {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.modules-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 50px;
  padding: 20px;
  width: 100%;
  flex: 1;
}

.module-circle {
  width: 250px;
  height: 250px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.module-circle::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  z-index: -1;
}

.module-circle .layer-1 {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #22474f;
  z-index: 1;
}

.module-circle .layer-2 {
  position: absolute;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  background: #23363d;
  z-index: 2;
}

.module-circle .layer-3 {
  position: absolute;
  width: 80%;
  height: 80%;
  border-radius: 50%;
  background: transparent;
  z-index: 3;
}

.module-circle:hover {
  transform: translateY(-15px) scale(1.05);
}

.module-circle:hover::after {
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.module-content {
  padding: 20px;
  z-index: 4;
  position: relative;
  background: transparent;
  border-radius: 50%;
  width: 70%;
  height: 70%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  color: white;
}

.module-content h2 {
  font-size: 22px;
  color: white;
  margin-bottom: 15px;
  font-weight: bold;
}

.module-content p {
  font-size: 14px;
  color: white;
  line-height: 1.5;
}

.module-icon {
  font-size: 48px;
  margin-bottom: 15px;
  color: white;
}

/* 移除注销按钮样式 */
/*
.logout-button {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}
*/

@media (max-width: 900px) {
  .modules-container {
    gap: 30px;
  }

  .module-circle {
    width: 200px;
    height: 200px;
  }
}

@media (max-width: 768px) {
  .modules-container {
    flex-direction: column;
    align-items: center;
  }

  .module-circle {
    width: 220px;
    height: 220px;
  }

  .main-title {
    font-size: 28px;
    margin: 20px 0;
  }
}

@media (max-width: 480px) {
  .module-circle {
    width: 180px;
    height: 180px;
  }

  .module-content h2 {
    font-size: 20px;
  }

  .module-icon {
    font-size: 36px;
  }
}
</style>